package com.irany.http.cd;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.irany.model.cd.CdTaskInfo;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * @author shujian.ou
 * @since 2021/5/17 0017 16:47
 */
public class CdTest {

    public static void main(String[] args) {
        String str = HttpUtil.get("https://paas-api-pro-alhz.inzm.com/dboy/api/v1/applications/all/?pagesize=10&current=2&search=&ordering=&organization=%E5%B0%91%E5%84%BF%E4%BA%8B%E4%B8%9A%E9%83%A8&app_type_id=&app_lang=&tag=&kong-identity=2AKgdd6c6J6hZfIa9GEAmeumX5ul60oK");

        JSONObject jsonObject = JSON.parseObject(str);

        JSONArray data = jsonObject.getJSONArray("data");

        List<CdTaskInfo> cdTaskInfos = JSON.parseArray(data.toJSONString(), CdTaskInfo.class);

        Map<String, List<CdTaskInfo>> orgCollect = cdTaskInfos.stream().collect(Collectors.groupingBy(CdTaskInfo::getOrganization));

        orgCollect.forEach((key,tasks)->{
            System.out.println("部门: " + key);
            tasks.forEach(t->{
                System.out.println(String.format("[id: %s, 服务名: %s, 创建人: %s, 创建时间: %s]", t.getId(), t.getGit_group(), t.getCreate_username(), t.getCreated_at()));
            });
            System.out.println("\n================================分割线================================\n");
        });
    }
}
